package xml;
/*XML Event correspondence
The events that Stax is reading come out as ints, which correspond to events from the XMLStreamConstants interface
Here are the correspondences:

1 START_ELEMENT
2 END_ELEMENT
3 PROCESSING_INSTRUCTION
4 CHARACTERS
5 COMMENT
6 SPACE
7 START_DOCUMENT
8 END_DOCUMENT
9 ENTITY_REFERENCE
10 ATTRIBUTE
11 DTD
12 CDATA
13 NAMESPACE
14 NOTATION_DECLARATION
15 ENTITY_DECLARATION
*/

import java.io.FileInputStream;

import java.io.IOException;
import java.io.FileNotFoundException;

import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

public class MockVotingXMLReader {
	
	private XMLInputFactory factory = XMLInputFactory.newInstance();
	private FileInputStream in;
	private XMLStreamReader parser;
			
	public MockVotingXMLReader(String fileName) throws FileNotFoundException, XMLStreamException {
		in = new FileInputStream(fileName);
		parser = factory.createXMLStreamReader(in);
	}
	
	public void endReading() throws XMLStreamException, IOException {
		parser.close();
		in.close();
	}

	public boolean hasNext() throws XMLStreamException {
		return parser.hasNext();
	}
	
	public String next() throws XMLStreamException {
		int i = parser.next();
		switch (i) {
			case 1: return "<" + parser.getLocalName() + ">"; //start element
			case 2: return "</" + parser.getLocalName() + ">"; //end element
			case 3: return ""; //processing instruction
			case 4: return parser.getText(); //characters
			case 5: return "<!--" + parser.getText() + "-->\n"; //comment
			case 6: return parser.getText(); //space
			case 7: return parser.getText(); // start document
			case 8: return ""; //end document
			case 9: return parser.getText(); // entity reference
			case 10: return ""; //attribute //major problem that attributes are unsupported
			case 11: return parser.getText(); //dtd
			case 12: return ""; //cdata
			case 13: return ""; //namespace
			case 14: return ""; //notation declaration
			case 15: return ""; //entity declaration
		}
		return "";
	}
	
}